package com.zhongcw.test.spring.boot.swagger2;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger2 原生配置类
 *
 * @author ZCW
 * @createTime 2018/3/27
 * @lastUpdateTime 2018/3/27 ZCW
 */
@Profile({"base"})
@Configuration
@EnableSwagger2
public class Swagger2Config {

    /**
     * 指定程序模块
     */
    @Bean
    public Docket commodityApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("商品管理")
                .apiInfo(commodityApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zhongcw.test.spring.boot.swagger2.commodity.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket employeeApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("员工管理")
                .apiInfo(employeeApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zhongcw.test.spring.boot.swagger2.employee.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建该Api的描述信息
     */
    private ApiInfo commodityApiInfo() {
        return new ApiInfoBuilder()
                .title("超市系统")
                .description("商品管理")
                .termsOfServiceUrl("http://www.zhongcw.com/")
                .contact(new Contact("钟长文", "http://www.shop.com", "zhong_cw@foxmail.com"))
                .version("1.0.0")
                .build();
    }

    private ApiInfo employeeApiInfo() {
        return new ApiInfoBuilder()
                .title("超市系统")
                .description("员工管理")
                .termsOfServiceUrl("http://www.yangchao.com/")
                .contact(new Contact("杨超", "http://www.shop.com", "yangchao@foxmail.com"))
                .version("1.0.0")
                .build();
    }

}
